<?php

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Request;
use Laravel\Sanctum\HasApiTokens;

class DoctorPatientModel extends BaseModel {

    protected static function booted()
    {
        parent::booted();
    }

    public function __construct(array $attributes = [])
    {
        parent::__construct($attributes);
        $this->connection = Request::header('Environment') ?: 'oms_prod';
    }

    protected $table = "dtrd_rl_doctor_patient";
    protected $primaryKey = "data_id";
    protected $connection = 'oms_prod';


    public function patient(){
        // hasOne(被关联的名命空间，关联外键，关联的主键)
        return $this->hasOne(PatientModel::class,'data_id','patient_id');
    }

    public function doctor()
    {
        return $this->hasOne(DoctorModel::class,'data_id','doctor_id');
    }
}
